import axios from '@/utils/request'
export default {
  Staff: {
    list: {
      export: {
        query: {
          '@display': `{
            'id' : 'entity.getId()',
            'user' : 'entity.getUser().__toString()',
            'store' : 'entity.getStore().__toString()',
            'squad' : 'entity.getSquad().__toString()',
            'team' : 'entity.getSquad().getTeam().__toString()',
            'name' : 'entity.getName()',
            'balance' : 'entity.getUser().getBalance().getAmount()',
            'phone' : 'entity.getPhone()'
          }`,
          limit: 10000000
        },
        label: {
          'id': '工号',
          'user': '绑定用户',
          'store': '门店',
          'squad': '小队',
          'team': '团队',
          'name': '姓名',
          'balance': '账号余额',
          'phone': '电话'
        }
      },
      query: {
        '@expands': "['entity.user.balance']"
      },
      disabled_actions: [],
      list_filter: {
        id: {
          expression: 'entity.getId() == ":value"',
          label: 'id',
          type: 'input'
        },
        'phone': '电话',
        'store.id': () => {
          return axios
            .get(`/manage/stores`)
            .then(res =>
              Object.assign({ __label: '门店' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
        'squad.id': () => {
          return axios
            .get(`/manage/squads`)
            .then(res =>
              Object.assign({ __label: '小队' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
        'squad.team.id': () => {
          return axios
            .get(`/manage/teams`)
            .then(res =>
              Object.assign({ __label: '团队' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
        name: {
          expression: `entity.getName() matches ":value"`,
          label: '名称',
          type: 'input'
        },
        enabled: {
          expression: 'entity.getEnabled() :value 0',
          label: '状态',
          data: [
            { value: '>', label: '在职' },
            { value: '==', label: '离职' }
          ]
        }
      },
      list_display: [
        'id',
        'user',
        'store',
        { property: 'squad', label: '小队' },
        'name',
        { property: 'user.__metadata.balance.__metadata.amount', label: '余额' },
        'phone',
        {
          property: 'weightType',
          label: '模式',
          component: {
            props: ['data'],
            render(h) {
              return (
                <div>{this.data == 1 ? '全职' : '兼职'}</div>
              )
            }
          }
        },
        { property: 'isManager', label: '门店负责人', editable: true },
        { property: 'enabled', label: '是否在职', editable: true }
      ]
    },
    form: {
      fields: [
        'store',
        { property: 'user' },
        'phone',
        'name',
        {
          property: 'weightType',
          field_options: {label: '模式'},
          required: true,
          default_value: 0,
          component: {
            props: ['form', 'property'],
            render(h) {
              return (
                <el-select v-model={this.form[this.property]} filterable>{
                  [
                    { label: '全职', value: 1 },
                    { label: '兼职', value: 0 }
                  ]
                    .map(status => {
                      return <el-option key={status.value} label={status.label} value={status.value} />
                    })
                }</el-select>
              )
            }
          }
        },
        { property: 'squad', field_options: { label: '所属小队' }, required: false },
        { property: 'isManager', field_options: { label: '门店负责人' }, required: false },
        { property: 'enabled', field_options: { label: '是否在职' }, default_value: true }
      ]
    }
  }
}

